package com.poi.tl.sample.quickstart.app.tags;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.Tables;
import com.deepoove.poi.data.style.BorderStyle;
import com.poi.tl.sample.quickstart.consts.AppConsts;
import java.io.FileOutputStream;
import java.util.HashMap;
import org.springframework.core.io.ClassPathResource;

public class _4_1BaseTableExport {

  public static void main(String[] args) throws Exception {
    ClassPathResource templateFile = new ClassPathResource(AppConsts.TAG_TEMPLATE_CLASS_PATH + "_4table_template.docx");
    String outFile = AppConsts.EXPORT_PATH + "_4_1_base_table_template_output.docx";

    // 1 	compile 编译模板
    XWPFTemplate template = XWPFTemplate.compile(templateFile.getInputStream()).render(
        // 2 render 渲染数据
        new HashMap<String, Object>(){{
          // 一个2行2列的表格
          put("table0", Tables.of(new String[][] {
              new String[] { "00", "01" },
              new String[] { "10", "11" }
          }).border(BorderStyle.DEFAULT).create());
        }});
    // 3 write 输出到流
    template.writeAndClose(new FileOutputStream(outFile));
  }

}
